export default {
  created(el, binding) {
    // console.log("created", el)
  },
  mounted(el, binding) {
    if (!binding.value) {
      return false
    }
    let dragDom = el.querySelector(".dialog_content")
    let dialogHeaderEl = el.querySelector(".dialog_drag")
    dialogHeaderEl.style.cursor = 'move';
    const sty = dialogHeaderEl.currentStyle || window.getComputedStyle(dialogHeaderEl, null);
    dialogHeaderEl.style.position = 'absolute';
    dialogHeaderEl.style.marginTop = 0;
    dialogHeaderEl.onmousedown = function (e) {
      console.log("e.clientX",e.clientX)
      const disX = e.clientX - dialogHeaderEl.offsetLeft
      const disY = e.clientY - dialogHeaderEl.offsetTop;
      // 鼠标拖拽事件
      document.onmousemove = function (e) {
        // console.log("disX",e.clientX - disX)
        // 通过事件委托，计算移动的距离 （开始拖拽至结束拖拽的距离）
        let l = e.clientX - disX;
        let t = e.clientY - disY;
        if (l < 0) {
          l = 0
        } else if (l > (dragDom.clientWidth - dialogHeaderEl.clientWidth)) {
          l = dragDom.clientWidth - dialogHeaderEl.clientWidth
        }
        if (t < 0) {
          t = 0
        } else if (t > (dragDom.clientHeight - dialogHeaderEl.clientHeight)) {
          t = dragDom.clientHeight - dialogHeaderEl.clientHeight
        }
        // 移动当前元素
        dialogHeaderEl.style.left = `${l}px`;
        dialogHeaderEl.style.top = `${t}px`;

      };
      document.onmouseup = function (e) {
        document.onmousemove = null;
        document.onmouseup = null;
      };
      return false
    }
  }
}